﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Linq;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using FalconSystemCatalogWebsite.ClassManager;



public partial class Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string serial;
            if (Request.Params["Serial"] == null)                
                serial = System.Configuration.ConfigurationManager.AppSettings["Serial"];
            else
                serial = Request.QueryString["Serial"];

            using (var Provider = new FalconSystemModel.FalconSystemProvider())
            {
                FalconSystemModel.Company companyEntity = Provider.Companies.FirstOrDefault(f => f.GUID == serial);
                lblCompany.InnerText = companyEntity.Name;

                FalconSystemCatalogWebsite.StockFilesManagerService.StockFilesManagerServiceClient stockFilesManagerServiceClient = new FalconSystemCatalogWebsite.StockFilesManagerService.StockFilesManagerServiceClient();
                byte[] logo = stockFilesManagerServiceClient.GetCompanyLogo(companyEntity.CompanyID);
                CompanyLogoPreviewImage.DataValue = logo;
                CompanyLogoPreviewImage.Height = Unit.Parse("100");

                //Session
                SessionManager sessionManager = new SessionManager();
                sessionManager.CompanyID = companyEntity.CompanyID;
                sessionManager.CompanyName = companyEntity.Name;
                sessionManager.CompanyLogo = companyEntity.Logo;
                sessionManager.Serial = companyEntity.GUID;

                HttpContext.Current.Session["SessionManager"] = sessionManager;

            }

            


            rmMenu.Items[0].ImageUrl = "../../Template/Icons/16px/falcon_16x16.png";                

            //Tree Categories
            Telerik.Web.UI.RadMenuItem menuItem = new Telerik.Web.UI.RadMenuItem();
            menuItem.ImageUrl = "../../Template/Icons/16px/sign-up-icon.png";
            menuItem.Value = "Pages/StockByCategories.aspx";            
            menuItem.Text ="Lista de Productos";
            menuItem.ToolTip = "Todas las categorías";
            menuItem.Attributes.Add("Width", System.Configuration.ConfigurationManager.AppSettings["StockByCategoriesWindowWidth"]);
            menuItem.Attributes.Add("Height", System.Configuration.ConfigurationManager.AppSettings["StockByCategoriesWindowHeight"]);
            menuItem.Attributes.Add("PosX", System.Configuration.ConfigurationManager.AppSettings["StockByCategoriesWindowPosX"]);
            menuItem.Attributes.Add("PosY", System.Configuration.ConfigurationManager.AppSettings["StockByCategoriesWindowPosY"]);
            menuItem.Attributes.Add("Page", "Categories.aspx");

            rmMenu.Items[0].Items.Add(menuItem);

        }
    }
}
